console.log("registration.js is working");
$(document).ready(function() {
	$("#registration-button").click(function(){
		
		var name      	= $('#register input[name="name"]').attr("value");
		var bday_month	= $('#register select[name="bday_month"]').attr("value");
		var bday_day	= $('#register select[name="bday_day"]').attr("value");
		var bday_year	= $('#register select[name="bday_year"]').attr("value");
		var group  	  	= $('#register input[name="group"]').attr("value");
		var email      	= $('#register input[name="email"]').attr("value");
		var password  	= $('#register input[name="password"]').attr("value");
		var confirm     = $('#register input[name="confirm"]').attr("value");
		console.log(name);
		var kk=name.replace(/\s+$/,"");
		var vaildname=kk.replace(/\s+/g," ");
		var name_words=vaildname.split(" ");
		console.log(name_words);
			if(name_words.length!=3){
					console.error("Invaild Name!");
					$("#name").css("color","red");
					}else
						{
							$("#name").css("color","black");
								if(bday_day=="Day" || bday_year=="Year" || bday_month=="Month") $("#birthday").css("color","red");
								 else{
									 	$("#birthday").css("color","black");
										if(confirm!=password)
											{
												console.error("Password Not Match!");
												$("#password").css("color","red");
											}
										else
											{
												$("#password").css("color","black");
												$.ajax({
												  type	: "GET",
												  url	: "/api/users/create",
												  data: {
														name		:vaildname,
														month		:bday_month,
														day			:bday_day,
														year		:bday_year,
														group		:group,
														password	:password,
														email		:email
												  		}
												}).done(function( result )
														{
															if(result.error)
																{
																	console.error(result.error.type);
																	if(result.error.type=="password") { $("#password").css("color","red") }
																	else{$(".password").css("color","black") }
																	if(result.error.type=="email") { $("#Email").css("color","red")}
																	else{$("#email").css("color","black") }
																}
															else{
																	console.dir(result);
																	$('#register').css("display","none");
																	$('#temp').html("Registred...Now you can log in");
																};
														});//for done
											};//for password else
								 	}; //for bday else
						};//for name else
	});//for click function
});//for ready